#ifndef PROCSYS_H
#define PROCSYS_H

#include <string>
#include <ostream>
#include <vector>

#include "utils.h"


/**
* @brief The CpuInfoFragment struct
* 代表"/proc/cpuinfo"中的一个processor中的内容，
* 原样载入，不做trim之外的其他操作
*/
struct SysCpuInfoFragment
{
    std::string processor;
    std::string vendor_id;
    std::string cpu_family;
    std::string model;
    std::string model_name;
    std::string stepping;
    std::string microcode;
    std::string cpu_MHz;
    std::string cache_size;
    std::string physical_id;
    std::string siblings;
    std::string core_id;
    std::string cpu_cores;
    std::string apicid;
    std::string initial_apicid;
    std::string fpu;
    std::string fpu_exception;
    std::string cpuid_level;
    std::string wp;
    std::string flags;
    std::string bogomips;
    std::string clflush_size;
    std::string cache_alignment;
    std::string address_sizes;
    std::string power_management;

    void loadFromText(const std::string &);

};

/**
 * @brief The CpuInfoFileContent struct
 * 存放"/proc/cpuinfo"文件的内容
 */
struct CpuInfoFileContent
{
    std::vector<SysCpuInfoFragment> vec;

    /**
     * @brief loadFromText 从字符串载入内容
     * @param text 保存着相关内容的字符串
     *
     * 拆分读取文件的逻辑和解析内容的逻辑，便于测试
     */
    void loadFromText(const std::string &text);

    /**
     * @brief loadFromSys
     * 从系统提供的"/proc/cpuinfo"文件载入内容
     */
    void loadFromSys()
    {
        loadFromText(getFileContent("/proc/cpuinfo"));
    }

};

/**
 * @brief The CpuStatFileContent struct
 * 存放"/proc/stat"文件的内容
 */
struct SysStatFileContent
{
    std::string cpu;
    std::vector<std::string> cpuN;
    std::string intr;
    std::string ctxt;
    std::string btime;
    std::string processes;
    std::string procs_running;
    std::string procs_blocked;
    std::string softirq;

    void loadFromText(const std::string &text);

    void loadFromSys()
    {
        loadFromText(getFileContent("/proc/stat"));
    }
};


#endif // PROCSYS_H
